from django.shortcuts import render
from rest_framework.filters import OrderingFilter
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination

from goods.models import SKU
from goods.serializers import SKUSerializers
from goods.utils import StandardResultsSetPagination


class SKUListView(ListAPIView):
    serializer_class = SKUSerializers
    pagination_class = StandardResultsSetPagination
    filter_backends = [OrderingFilter]
    ordering_fields = ['price', 'create_time', 'sales']

    def get_queryset(self):
        pk = self.kwargs['pk']
        return SKU.objects.filter(category_id=pk,is_launched=True)



